package service

import (
	"ai/internal/aiserver/request"
	"ai/internal/db/models"
	"ai/internal/repository"
)

type QuestionService struct {
	questionRepo *repository.QuestionRepository
}

func NewQuestionService(questionRepo *repository.QuestionRepository) *QuestionService {
	return &QuestionService{questionRepo: questionRepo}
}

func (s *QuestionService) AddQuestion(questionText, questionType string, answers []request.ReqAnswer) error {
	question := models.Question{
		Text:         questionText,
		QuestionType: questionType,
	}
	question_answers := make([]models.Answer, len(answers))
	for i, answer := range answers {
		question_answers[i] = models.Answer{
			Text:      answer.Answer,
			IsCorrect: answer.IsCorrect,
		}
	}
	question.Answers = question_answers
	return s.questionRepo.AddQuestion(&question)
}

func (s *QuestionService) GetQuestions() ([]models.Question, error) {
	return s.questionRepo.ListQuestions()
}
